package com.springboot.asyn.service;

import com.springboot.asyn.AsynApplication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class Send1 {
    @Autowired
    JavaMailSenderImpl javaMailSender;

    @Async
    public List<String> send1(){
        ArrayList<String> list = new ArrayList<>();
        Logger logger = LoggerFactory.getLogger(AsynApplication.class);
        SimpleMailMessage message = new SimpleMailMessage();

        message.setSubject("今晚开会");
        message.setText("今晚7点30开会");
        message.setTo("c18245842939@163.com");
        message.setFrom("1040395857@qq.com");

        try {
            for (int i = 0; i < 100; i++) {
                javaMailSender.send(message);
                javaMailSender.createMimeMessage();
                logger.info("发送成功");
                list.add("发送成功");
            }
        } catch (Exception e) {
            logger.error("发送失败");
            list.add("发送失败");
        }

        return list;
    }



}
